< previous page page_586 next page >

Page 586
d6ef40187df115e88326dbc94f09ab9a.gif d6ef40187df115e88326dbc94f09ab9a.gif
More About Filters
d6ef40187df115e88326dbc94f09ab9a.gif d6ef40187df115e88326dbc94f09ab9a.gif
The Filter condition of the dynaset has no effect on the current dynasetonly on secondary dynasets created from the current one. The only way to "filter" the existing recordset is to move through the recordset with the Find methods. By setting the Find condition to your Filter condition, you process only the records you want.
d6ef40187df115e88326dbc94f09ab9a.gif d6ef40187df115e88326dbc94f09ab9a.gif
If you work with only the filtered dynaset, creating the required dynaset using the appropriate SQL clause in the OpenRecordset method is more efficient.
Setting the Sort Property
As with the Filter property, the Sort property is available only for dynasets and snapshots. Although the following discussion refers only to dynasets, the same statements apply to snapshots. You can specify the Sort property by providing the field names and order (ascending or descending) for the fields on which the dynaset is to be sorted. You can specify any field or combination of fields in the current dynaset. The Sort condition is similar to the ORDER BY clause of a SQL statement. You can use the Sort property to create a recordset much like you used the Filter property in the preceding section. For example, the following statement specifies a sort order of last name followed by the birthdate:
rsTest.Sort = "LastName, Birthday"
CAUTION
When you are specifying a multiple field sort, the order of the fields is important. A sort on first name and then last name yields different results than a sort on last name and then first name.

You can also achieve the same results of a sorted dynaset in a more efficient manner by specifying the ORDER BY clause of the SQL statement used to create the dynaset.
Creating a New Index
In the earlier section "Setting the Current Index in a Table," you learned how to specify the index used in a database search. If the index you want does not exist, you can create it by using a few lines of code.
First, use the CreateIndex function of a Table object to create the new index object. Then add fields to the index object with its Append method, as in the following lines of code:
Dim Idx1 As Index
Dim Fld1 As Field
Set Idx1 = NewTbl.CreateIndex("Zip_Code")
Set Fld1 = Idx1.CreateField("Zip")
Idx1.Fields.Append Fld1
The preceeding lines of code set up a new index called "Zip Code." In order to use this index, you need to append it to the Indexes collection of the table and set the table object's Index property to the name of the index:

 
< previous page page_586 next page >